<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/instance_not_found_exception.php");
require_once("lib/exception/privileges_exception.php");

require_once("lib/model/action.php");
require_once("model/article_image/dao/article_image_dao_factory.php");
require_once("model/article_image/to/article_image_to.php");

class Remove_image_action implements Action {

	private $image_number;
	private $autor_login;
	
	public function __construct($image_number, $autor_login) {
		
		$this->image_number = $image_number;
		$this->autor_login = $autor_login;
	}
	
	public function do_execute() {
		try {
			$dao = Article_image_dao_factory::singleton()->get_dao();
			$image_to = $dao->find_by_image_number($this->image_number);			
			if ($image_to->get_autor_login() == $this->autor_login) {
				$dao->remove($this->image_number);			
			}
			else
				throw new Privileges_exception('remove image');
		}
		catch (Instance_not_found_exception $e) {
			throw new Model_exception($e);
		}
		catch (Privileges_exception $e) {
			throw $e;
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}

?>
